<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="minimal-ui,width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title>订单详情-{$webseting.web_title}</title>
    <link href="__PUBLIC__/wap/css/rest.css"  rel="stylesheet">
    <link href="__PUBLIC__/wap/css/user.css"  rel="stylesheet">
    <link href="__PUBLIC__/wap/css/detailedTracking.css"  rel="stylesheet">
</head>
<body id="body">
    <header id="header" class="u-header clearfix">
        <div class="u-hd-left f-left">
            <a href="{:U('wap/goodsorder/index')}" class="J_backToPrev"><span class="u-icon-px i-hd-back"></span></a>
        </div>
        <div class="u-hd-tit"><span>订单详情</span></div>
    </header>
    <div class="fwrap">
        <section class="order-con">
            <ul class="order-list">
                <li>
                    <div class="order-box">
                        <div class="order-width">
                            <p>订单编号：{$data.order_sn}</p>
                            <p>订单金额：￥{$data.order_amount}</p>
                            <p>订单日期：{$data.add_time|date="Y-m-d H:i:s",###}</p>
                             <p>支付状态：
                               <if condition="$data.pay_status eq 2">
                                 <if condition="$data.offline eq 1">
                                  货到付款
                                  <else/>
                                  {$pay_status[$data['pay_status']]}
                                 </if> 
                               <else/>
                                {$pay_status[$data['pay_status']]}
                               </if> 
                               </p>
                             <if condition="$data.pay_status eq 2">
                                <p> 支付时间: {$data.pay_time|date="Y-m-d H:i:s",###}</p>
                            </if>
                            
                        </div>

                         <div class="order-width">
                            <if condition="$data.pay_status eq 2">
                             <p>订单状态：{$order_status[$data['order_status']]} </p>
                              <if condition="$data.shipping_status eq 1">
                             <p>订单确认时间：{$data.confirm_time|date="Y-m-d H:i:s",###}</p>
                             </if>
                            </if>  
                             
                    <if condition="$data.pay_status eq 2">
                         <p>商品配送情况：{$shipping_status[$data['shipping_status']]} </p>
                          <if condition="(in_array($data['shipping_status'],array('1','2')))">
                         <p> 商品配送时间:{$data.shipping_time|date="Y-m-d H:i:s",###}</p>
                         </if>
      
                         <if condition="(in_array($data['shipping_status'],array('1','2')))">
                         {//1，已发货；2，已收货}
                         <p>发货单号：{$data.invoice_no} </p>
                         </if>
                    </if>
                             
                        </div>
                      <!--  <div class="pay-button">
                            <a class="pay-order" href="#">订单跟踪</a>
                            <a class="pay-order" href="#">满意度评价</a>
                        </div>-->
                    </div>
                </li>
                <li>
                    <div class="order-box">
                        <ul class="book-list">
                           <volist name="order_goods" id="vo">
                            <li class="border-bottom">
                                <a href="{:U('Wap/goods/goods_detail',array('id'=>$vo['goods_id']))}">
                                    <div class="order-msg">
                                        <img src="{:U('wap/index/get_thumbs',array('auto'=>64))}?img={$vo.goods_image}" class="img_ware">
                                        <div class="order-msg">
                                            <p class="title"> {$vo.goods_name} {$vo.goods_attr}</p>
                                            <p class="price"> ¥{$vo.goods_price}<!-- /<s style="text-decoration: line-through; color:#999;">¥{$vo.market_price}</s> -->
                                            <span></span></p>
                                            <p class="order-data">X{$vo.goods_number}</p>
                                        </div>
                                    </div>
                                </a>
                            </li>
                       </volist>

                        </ul>
                    </div>
                </li>
                 <li>
                    <div class="order-box">
                        <div class="order-width">

                           <p class="border-bottom usr-name">
                              收货人: {$data.consignee} <!-- 收货人姓名 -->
                                         <!-- 收货人电话 -->
                                <span class="fr">{$data.mobile}</span>
                            </p>
                                            <!-- 收货人地址 -->
                            <p class="usr-addr">{$data.address}</p>

                        </div>
                    </div>
                </li>
                <li>
                    <div class="order-box">
                        <div class="order-width">
                           
                            <p>商品金额:<span class="fr red">￥{$data['order_amount_all']-$data['shipping_fee']}<!-- /<s style="text-decoration: line-through; color:#999;">￥{$data.goods_amount}</s> --></span></p>
                            <p>运费:<span class="fr red">￥{$data.shipping_fee}</span></p>
                             <if condition="$data['discount_price'] gt 0">
                              <p>折扣金额:<span class="fr red">-￥{$data['discount_price']}</span></p>
                             </if>
                             <if condition="$data['surplus'] gt 0">
                            <p>余额支付金额:<span class="fr red">￥{$data['surplus']}</span></p>
                             </if>
                            <!-- <p class="border-bottom">运费:<span class="fr red">￥0.00</span></p> -->
                            <if condition="($data['order_amount']-$data['surplus']) gt 0">
                              <if condition="$data['pay_status'] eq 2">
                                 <?php if($data['offline'] == 1){ ?>
                                 <p>货到付款:<span class="fr red">￥{$data['offline_money']}</span></p>

                                   <?php if($data['order_amount']-$data['surplus']-$data['offline_money'] > 0){ ?>
                                         <p>微信支付:<span class="fr red">￥{$data['order_amount']-$data['surplus']-$data['offline_money']}</span></p>
                                    <?php  }  ?>

                                 <?php }else{ ?>
                                 <p>微信支付:<span class="fr red">￥{$data['order_amount']-$data['surplus']}</span></p>
                                   <?php  }  ?>

                              <else/>
                               <p>待付金额:<span class="fr red">￥{$data['order_amount']-$data['surplus']}</span></p>
                             </if>
                             <else/>
                             <p>支付金额:<span class="fr red">￥{$data.order_amount}</span></p>
                          </if>
                           
                        </div>
                    </div>
                </li>
                <if condition="in_array($data['order_state'],array('delivered','received'))">
                <li>
                    <div class="order-box">
                        <div class="order-width">
                            <p class="border-bottom usr-name">配送信息：{$shipping_status[$data[shipping_status]]}<span class="fr"></span></p>
                            <p>配送单号: {$data.invoice_no}</p>
                            <if condition="$data.best_time neq null">
                            <p>送货时间: {$data.best_time}</p>
                            </if>
                            <p>配送时间: {$data.shipping_time|date="Y-m-d H:i:s",###}</p>
                        </div>
                    </div>
                </li>
            </if>
                 
                    <if condition="$data['order_state'] eq 'nopay'">

                <form action="" role="form" id="form2" novalidate="novalidate" method="post" onSubmit="return false;">
                   <li>
                    <div class="order-box">
                        <div class="order-width">
                            <p class="border-bottom usr-name">付款方式:<span class="fr">微信支付</span></p>
                             <div class="ui-form ui-border-b" style="margin-bottom: 0;border-bottom: none; ">
                              <div class="ui-form ui-border-b" style="text-align: left;line-height: 40px;">
                              <input id="pay_online"  class="pay_type" name="pay_type" type="radio" value="pay_online" checked="checked" style=" margin-left: 10px;">
                              <label for="pay_online">在线支付</label>
                              <span class="fr" style="margin-right:10px;">￥{$data['order_amount']-$data['surplus']}</span>
                             </div>
                           <if condition="$offline_money gt 0">
                            <div class="ui-form ui-border-b" style="text-align: left;line-height: 40px; border-bottom: none; margin-bottom: 0;">
                              <input id="pay_offline" class="pay_type" name="pay_type" type="radio" value="pay_offline" style=" margin-left: 10px;" 
                              data-pay="<?php if(($data['order_amount']-$data['surplus']) ==$offline_money)echo '0';else echo '1'; ?>">
                              <label for="pay_offline">货到付款</label>
                              <span class="fr" style="margin-right:10px;">货到付款:￥{$offline_money}
                                <?php if($online_money > 0){ ?>
                                在线支付:￥{$online_money}
                                <?php } ?>
                              </span>
                           </div>
                           </if>
                         </div>
                          
                        </div>
                    </div>
                </li>

                    <if condition="$balance egt 1">
                  <li class="use_balance_pay">
 
                      <div class="ui-form ui-border-b">
                          <div class="ui-form ui-border-b" style="text-align: left;line-height: 40px;">
                              <input id="use_balance" name="use_balance" type="checkbox" value="1" checked="checked" style=" margin-left: 10px;">
                              <label for="use_balance">使用余额支付</label>
                              <span class="fr" style="margin-right:10px;">可用余额：￥{$balance}</span>
                          </div>
                           
                          <div class="ui-form-item ui-border-b input_password">
                              <label style="width: 85px;">输入登录密码</label>
                              <input style="padding: 12px 0 0 91px;" name="mem_password" id="mem_password" type="password" value="" placeholder="输入登录密码">
                          </div>
                      </div>
                  </li>
                <else/>
                 <input name="use_balance" type="checkbox" value="1"   style=" display:none">
                </if>
                <input name="order_id" id="order_id" type="hidden" value="{$data.order_id}" placeholder="">
                 <li>
                    <div class="order-box">
                        <div class="order-width">
                             <a href="javascript:void(0);" id="go_pay" data="{$data.order_id}"   data-tpa="GOTO_CHECKOUT" class="new-abtn-type new-mg-tb30 phone_log_btn">
                              去付款
                               </a>
                        </div>
                    </div>
                </li>
                    </form>
               <elseif condition="$data['order_state'] eq 'delivered' && $ref_all eq 0"/>
                 <li class="delivered_html">
                    <div class="order-box">
                       <span  style="color:red;">*确认收货后订单不可退换！</span>
                        <div class="order-width">
                             <a href="javascript:void(0);" data="{$data.order_id}" data-tpa="GOTO_CHECKOUT" class="new-abtn-type new-mg-tb30 delivered">
                               确认收货
                               </a>
                        </div>
                    </div>
                </li>  
             </if>
                
                <!-- <li>
                    <div class="order-box">
                        <div class="order-width">
                            <p class="border-bottom usr-name">配送信息<span class="fr"></span></p>
                            <p>配送方式: 普通快递</p>
                            <p>送货时间: 只工作日送货（双休日、假日不用送）</p>
                            <p>配送时间: </p>
                        </div>
                    </div>
                </li> -->
            </ul>
        </section>
    </div>
    
  <include file="Public/wap_javascript" />    
       <!--微信分享-->    
 <include file="Public/share_weixin" />


    <script>
        jQuery(document).ready(function() {
            //FormValidator.init();
            jQuery.validator.addMethod("passwordRequired", function(value) {
                var use_balance=$('input[name="use_balance"]').prop('checked');
                var ret=true;
                if(use_balance){
                    if(!value){
                        ret=false;
                    }
                }
                return ret;
            });

            $("#form2").validate({
                rules: {
                    mem_password: {
                        passwordRequired: true,
                        rangelength: [6, 20]
                    }
                },
                messages: {
                    mem_password:{
                        passwordRequired:'<span class="icon-warning icon_warning"></span>&nbsp;请输入密码',
                        rangelength:'<span class="icon-warning icon_warning"></span>&nbsp;密码请保持6-20位'
                    }
                },
                focusInvalid:false,
                success: function(label) {
                    // set  as text for IE 
                    // alert('ok'); 
                    //label.html(" ").addClass("checked"); 
                },
                /*执行ajaxsubmit  */
                submitHandler: function(editform) {

                    var options = {
                        url :  "<?php echo U('Wap/goodsorder/go_pay'); ?>",
                        type : "post" ,
                        dataType:'json',
                        target : "#loader",
                        error: function(){layer.msg("服务器没有返回数据，可能服务器忙，请重试",{icon:5});},
                        onwait : "正在处理信息，请稍候...",
                        success: function(response){
                            // console.log(response);
                            //$("#loader").fadeIn(500).html(response.data).fadeOut(500); 
                            //$('#editform').hide(2000); 
                            if(response.status==1){
                              //layer.msg('支付成功',{icon:6});
                              if(response.need_pay==1){
                               /*  window.location.href="<?php  echo U('Wap/Mallpayment/index',array('pay_sn'=>$data['order_sn']));?>";*/
                               //if(response.pay_url!='' && typeof(response.pay_url)!=undefined){
                                    // window.location.href=response.pay_url;
            									//go_weixin_pay();
            									get_weixin_pay(response.pay_url);
                                //  }else{
                                  //    layer.msg('系统错误请稍候再试', {icon: 5});
                                //  }
                                //layer.msg('修改成功，请重新登录',{icon:6});
                              }else{
                                layer.msg('支付成功',{icon:6,time: 1500},function(){
                                     window.location.href="<?php  echo U('wap/goodsorder/order_detail',array('id'=>$data['order_id']));?>";
                                });
                              }
                               
                               /* layer.msg("修改成功，请重新登录。",{icon:6},function(){
                                  window.location.href="<?php echo U('Wap/Login/loginout'); ?>";
                                });*/
                            }else{
                                layer.msg(response.error,{icon:5});
                            }
                        }
                    };
                    setTimeout((function(opt){
                        return function(){
                            layer.msg("正在处理信息，请稍候...",{time:100000});
                            $('#form2').ajaxSubmit(opt);
                        }
                    })(options), 300);
                    return false;
                }

            });

            $('#go_pay').click(function(){

                var use_balance=$('input[name="use_balance"]').prop('checked');
                 var pay_type=$('input[name="pay_type"]:checked').val();

               if(pay_type=='pay_online'){
                $('#form2').submit();
               //在线支付
               /* if(use_balance){
                  $('#form2').submit();
                }else{
                  go_weixin_pay();
                }*/
               }else{
                 //货到付款
                 $('#form2').submit();
               }
            });



        });

    </script>
    <script type="text/javascript">
   $(function(){
    //确认收货
    $('.delivered').click(function(){
       var order_id=$(this).attr('data');
        layer.confirm('是否确认收货？确认收货后订单不可退换！', {
            btn: ['确定','取消'] //按钮
      }, function(){
          if(order_id){
            $.ajax({
                url: "{:U('wap/goodsorder/order_delivered')}",
                type:'post',
                data: {order_id:order_id},
                dataType: 'json',
                success: function(data){
                  if(data.status==1){
                    //alert("确认收货成功");
                    layer.msg('确认收货成功', {icon: 6,time: 1500});
                    $('.delivered_html').remove();
                  }else{
                    layer.msg(data.error, {icon: 5});
                    //alert(data.error)
                  }
                }
               });
          }else{
             layer.msg('系统繁忙,请稍后再试', {icon: 5});
            //alert('系统繁忙,请稍后再试')
          }
      }, function(){
          
      });

    });
 $('#use_balance').click(function(){
  set_use_balan();
}); 
 set_use_balan();

  $('input[name="pay_type"]').change(function(){
  set_pay_type();
}); 
  set_pay_type();
});
   function set_use_balan(){
 var use_balance=$('#use_balance').prop('checked');
   if(use_balance){
    $(".input_password").show();
   }else{
    $(".input_password").hide();
   }
   }
    function set_pay_type(){

 var pay_type=$('input[name="pay_type"]:checked').val();
   if(pay_type=='pay_online'){
    $(".use_balance_pay").show();
    $('#use_balance').prop('checked',true);
     set_use_balan()
   }else{
    var need_pay=$('input[name="pay_type"]:checked').attr('data-pay');
    if(need_pay==1){
      
     }else{
       $(".use_balance_pay").hide();
      $('#use_balance').prop('checked',false);
       set_use_balan()
     }
   }
   }
 </script>

 <script type="text/javascript"> 
function get_weixin_pay(url){
    ///需要支付
    var pay_url="<?php echo 'http://'.$_SERVER['HTTP_HOST'].'/api/payment/wpay/jsapi_go_pay.php?pay_sn='.$data['order_sn']; ?>";
    window.location.href=pay_url+"&openid=<?php echo $_SESSION['user_open_id'];?>";
    return false;
   /* $.ajax({
        url: url,
        type:'get',
       // data: {order_id:order_id},
        dataType: 'json',
        success: function(data){
          if(data.status==1){
            //alert("确认收货成功");
             var pay_url="<?php echo 'http://'.$_SERVER['HTTP_HOST'].'/api/payment/wpay/jsapi_go_pay.php?pay_sn='.$data['order_sn']; ?>";
             window.location.href=pay_url+'&pay_amount='+data.pay_amount+'&payvalue='+data.payvalue;
          }else{
            layer.msg(data.error, {icon: 5});
            //alert(data.error)
          }
        }
       });*/
}
function go_weixin_pay(){
          layer.msg('连接FG峰购收银台....',{time: 100000});
                    $.ajax({
                      url: "{:U('wap/goodsorder/get_pay_url')}",
                      type:'get',
                      data: {pay_sn:'<?php echo $data['order_sn']; ?>',pay:'1'},
                      dataType: 'json',
                      success: function(data){
                        if(data.status==1){
                          if(data.pay_url!='' && typeof(data.pay_url)!=undefined){
							 get_weixin_pay(data.pay_url);
                          }else{
                              layer.msg('系统错误请稍候再试', {icon: 5});
                          }
                        }else{
                          layer.msg(data.error, {icon: 5});
                          //alert(data.error)
                        }
                      }
                     });
}
 </script>   
</body>
</html>